Hello and welcome back to our assessing about Victoria's thought element y's operations service.
None pay a raise.
And first of all let's create an NDA Ray from scratch with the function and peer daughter range and
NDP dollar range creates an array with integers and we can define that beginning and ending point.
So here we want to create an NDA array from one till eleven and it's by convention.
That's the beginning point the starting point us including and ending point is excluding So this is
very similar to the range function which we learned before so let's create the ending array and then
you can see a name.
P is not defined so first of all we have to import the manpower package.
So by default the number of package is not imported and before I accept that we typically we import
non pi S and P but yeah we do not have to make these abbreviations so we can also just say we want to
import an umpire and still not works because we didn't define M Ps but what we can do we can just write
out an umpire.
So the function is an umpire daughter range and then it works.
However the convention is to have an abbreviation so writing out always num PIs.
But a bit too much work for most of us.
So it makes definitely sense to have an abbreviation so important umpire as MP and then instead of having
to write out num pay every time we can just write and P
and they can see we have an umpire Ray from 1 until 10 including and what we can also do we can create
an umpire Ray from one till eleven excluding all ten including and only every second number is created.
So let's see how it works.
They can see it starting from 1 We get only every second number to 10.
So 1 3 5 7 9 so eleven is already excluded.
All right so in this lesson I want to highlight the difference between lists and umpire race when it
comes to element y's operations on first of all let's create a list L with four elements 1 2 3 and 4.
And our intention is to to multiply each element by two and if try to not just calculate l times to
and we do not get them the result we we actually intended.
You only get two copies of concatenated and if you want to make element y's operations we have to use
a for loop so we create an empty list and for element and l we have to multiply the element and appended
to the new list L1 and then we can print out the one with the multiplied elements 2 4 6 and 8 and we
also know that we cannot make an element y's addition.
So if we want to add two to each element in the list and to then Python drops us an error message.
All right so let's create an umpire Ray from 1 to 4 is 4 elements with the function NPI range 1 2 5
5 excluding we get an array with the 1 2 3 FA and now if we want to make an element y's operation so
we want to multiply each element by 2 we can do this simply by saying okay our ray times 2 and this
gives us element y's operation so one must multiply by 2 2 was multiplied by 2 Three was multiplied
by 2 and 4 was multiplied by 2 and they are we we didn't use any for loop or something it's just them
so-called vector rise the scalar operation here and also we can add each element with two that's no
problem and we can also square each element to the power of two.
So 1 2 the power of 2 gives us 1 to 2 the power of 2 gives us 4 3 2 the power of 2 gives us 9 and 4
2 the power to give the sixteen and our vector a an umpire Ray can also serve as an exponent so two
to the power of a gives us a vector of four elements so two to the power one is two to the two the power
of two gets for two to the power of three gas eight and two to the power of four gives us sixteen and
we can also take the square root of each element of a and also we can make an exponential motion with
the E so e to the power of a
and we can also calculate the natural logarithm of all elements of a.
Moreover we can also take the sum of all elements so one plus two plus three plus four.
There are some in the array method that some
now that actually three alternatives.
To sum up all elements of our array so we can use the n the Array method that some we can use the name
pi function and Pitot some and then in the brackets a and also we can use just the the sum function.
So some A.
This also works with lists gets also 10 and we can also calculate the number of elements and then ended
array by applying the attribute size so a dot size gives us far and that's actually the same functionality
than the length function which we already know.
And let's create a new an umpire ray with the elements minus two minus 1 minus 0 point 5 0 1 2 three
point five and assign the variable B and that's also the function end Pitot EPS and what MPD EPS does
it's actually calculate the absolute values of all elements so you can see here we have negative numbers
and these negative numbers are transformed to positive numbers to say so minus two is two minus one
this one minus 0 point five is oh point five and so on.
All right so let's create another array see with the elements minus one point seven minus one point
five minus 0 point 2 and so on and that's the function in P that C and what NPD out C told us actually
it element was rounding up all elements to the next higher integer.
So let's see what we get here.
So the next higher integer of minus one point seven is minus one and the next higher integer of minus
one point five is minus one and so on and for example here the next higher integer of 0 point 2 is one
that's also the possibility to have an element by rounding down with the function and P top floor.
So with Episode 4 we element elementals round down all elements to the next lower integer minus one
point seven gives minus two minus 0 point to guess minus 1 0 point to gives zero one point seven for
example I one and we can also round all elements with a given number of decimals.
So let's assume here we have an list with the minus three point two three minus open seven six.
And now we can define how many decimals we want to have.
And here we can define 1 so we can see here.
Now we rounded minus three point two three two minus three point two one point four four to one point
four and two point six five to two point six then we can.
Now we can also increase the number of decimals to to and I can also say I don't want to have any decimals.
Now you can see here.
So we have minus three minus one 1 and 3 so NPR US has actually the same functionality as the round
function as we already know.
All right.
So this is to for the time being in this session we learn back to rise or element y's operations with
an umpire race.
And this is quite easy and we don't need any for loops like with the pace and standard library.
And the next lesson we learn about indexing and slicing num pi raise so hope to see you there and your
next session.
By.